package com.example.a10928.weifriend.ui.personal_center

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.text.TextUtils
import com.example.a10928.weifriend.App
import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.util.L
import com.example.a10928.weifriend.util.RxUtil
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_edit_pw.*
import org.w3c.dom.Text

class EditPWActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit_pw)

        supportActionBar?.hide()

        activity_forget_bt.setOnClickListener {
            if(TextUtils.isEmpty(activity_old_password_et.text.toString())){
                L.t("请输入旧密码")
                return@setOnClickListener
            }
            if(TextUtils.isEmpty(activity_forget_password_et.text.toString())||
                    TextUtils.isEmpty(activity_forget_2password_et.text.toString())){
                L.t("请输入新密码")
                return@setOnClickListener
            }
            if( !activity_forget_password_et.text.toString().equals(activity_forget_2password_et.text.toString())){
                L.t("两次密码不一致")
                return@setOnClickListener
            }

            App.app().bpService.updatePassword(App.app().user.userId,
                    activity_old_password_et.text.toString(),
                    activity_forget_password_et.text.toString())
                    .compose(RxUtil.io2mainLoad(this))
                    .subscribe(
                            Consumer {
                                L.t("修改成功")
                                finish()
                            },
                            Consumer {
                                RxUtil.errorException(it)
                            }
                    )


        }



    }
}
